﻿using System;

namespace EmbeddedSharp.Core.Function.Maths {

    /// <summary>
    /// Returns the absolute value of a double-precision floating-point number.
    /// 
    /// Syntax: abs(number);
    /// 
    /// Example: abs(-1); # the result is 1
    /// </summary>
    [Function("abs", "Returns the absolute value of a double-precision floating-point number.", "a=abs(-1);", "a==1")]
    public class AbsNode : FuncNode {
        public AbsNode()
            : base() {
            base.Value = "abs";
        }

        public override object Evaluate() {
            double result = Convert.ToDouble(Parameters[0].Evaluate());

            return System.Math.Abs(result).ToString();
        }
    }
}
